home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all macintosh / quicktime for java / moviecallbacks / src / moviecallbacks.java
Encoding:
Java Source  |  2000-06-23  |  4.7 KB  |  153 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.io.IOException;
  11.  
  12. import quicktime.*;
  13. import quicktime.io.*;
  14. import quicktime.std.movies.*;
  15. import quicktime.app.display.QTCanvas;
  16. import quicktime.app.players.QTPlayer;
  17. import quicktime.std.*;
  18. import quicktime.vr.*;
  19.  
  20. public class MovieCallbacks extends Frame implements Errors {    
  21.     
  22.     public static void main (String args[]) {
  23.         try {
  24.             System.out.println ("Open a Multi-node VR Movie...");
  25.             QTSession.open (QTSession.kInitVR);
  26.                 //register handler for QTRuntimeExceptions
  27.             QTRuntimeException.registerHandler (new Handler());
  28.             
  29.             MovieCallbacks pm = new MovieCallbacks("QT in Java");
  30.             pm.pack();
  31.             pm.show();
  32.             pm.toFront();
  33.         } catch (QTException e) {
  34.             if (e.errorCode() == userCanceledErr) {
  35.                 QTSession.close();
  36.                 System.exit(0);
  37.             }
  38.             e.printStackTrace();
  39.             QTSession.close();
  40.         }
  41.     }
  42.  
  43.     MovieCallbacks (String title) throws QTException {
  44.         super (title);
  45.         
  46.         QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);
  47.  
  48.         OpenMovieFile movieFile = OpenMovieFile.asRead(qtf);
  49.         Movie m = Movie.fromFile (movieFile);
  50.         MovieController mc = new MovieController (m);
  51.         mc.setKeysEnabled (true);
  52.         
  53.         Track t = m.getQTVRTrack (1);
  54.         if (t != null) {    //setup VR callbacks
  55.             QTVRInstance vr = new QTVRInstance (t, mc);
  56.             vr.setEnteringNodeProc (new EnteringNode(), 0);
  57.             vr.setLeavingNodeProc (new LeavingNode(), 0);
  58.             vr.setMouseOverHotSpotProc (new HotSpot(), 0);
  59.             Interceptor ip = new Interceptor();
  60.             vr.installInterceptProc (QTVRConstants.kQTVRSetPanAngleSelector, ip, 0);
  61.             vr.installInterceptProc (QTVRConstants.kQTVRSetTiltAngleSelector, ip, 0);
  62.             vr.installInterceptProc (QTVRConstants.kQTVRSetFieldOfViewSelector, ip, 0);
  63.             vr.installInterceptProc (QTVRConstants.kQTVRSetViewCenterSelector, ip, 0);
  64.             vr.installInterceptProc (QTVRConstants.kQTVRTriggerHotSpotSelector, ip, 0);
  65.             vr.installInterceptProc (QTVRConstants.kQTVRGetHotSpotTypeSelector, ip, 0);
  66.         }
  67.         
  68.         // set up movie drawing callback
  69.         m.setDrawingCompleteProc (StdQTConstants.movieDrawingCallWhenChanged, new MovieDrawing());
  70.         // set up action filter
  71.         mc.setActionFilter (new PMFilter(), false);    //don't do idle events
  72.         
  73.         QTPlayer myQTPlayer = new QTPlayer (mc);
  74.         QTCanvas myQTCanvas = new QTCanvas();
  75.         add(myQTCanvas);            
  76.         myQTCanvas.setClient (myQTPlayer, true);
  77.         
  78.         addWindowListener(new WindowAdapter () {
  79.             public void windowClosing (WindowEvent e) {
  80.                 QTSession.close();
  81.                 dispose();
  82.             }
  83.  
  84.             public void windowClosed (WindowEvent e) { 
  85.                 System.exit(0);
  86.             }
  87.         });
  88.     }
  89.     
  90.     static class MovieDrawing implements MovieDrawingComplete {
  91.         public int execute (Movie m) {
  92.             System.out.println ("drawing:" + m);
  93.             return 0;
  94.         }
  95.     }    
  96.  
  97.     static class EnteringNode implements QTVREnteringNode {
  98.         public int execute (QTVRInstance vr, int nodeID) {
  99.             System.out.println (vr + ",entering:" + nodeID);
  100.             return 0;
  101.         }
  102.     }
  103.          
  104.     static class LeavingNode implements QTVRLeavingNode {
  105.         public int execute (QTVRInstance vr, int fromNodeID, int toNodeID, boolean[] cancel) {
  106.             System.out.println (vr + ",leaving:" + fromNodeID + ",entering:" + toNodeID);
  107.             // no error and Don't cancel leaving node
  108.                 // cancel[0] = true; -> this would cancel leaving the fromNode
  109.             return 0;
  110.         }
  111.     }
  112.     
  113.     static class HotSpot implements QTVRMouseOverHotSpot {
  114.         public int execute (QTVRInstance vr, int hotSpotID, int flags) {
  115.             System.out.println (vr + ",hotSpot:" + hotSpotID + ",flags=" + flags);
  116.             return 0;
  117.         }
  118.     }
  119.     
  120.     static class Interceptor implements QTVRInterceptor {
  121.         public boolean execute (QTVRInstance vr, QTVRInterceptRecord qtvrMsg) {
  122.             System.out.println (vr + "," + qtvrMsg);
  123.             return false;    //dont cancel default execution
  124.         }
  125.     }
  126.  
  127.     static class PMFilter extends ActionFilter {
  128.         public boolean execute (MovieController mc, int action) { 
  129.             System.out.println (mc + "," + "action:" + action);
  130.             return false; 
  131.         }
  132.  
  133.         public boolean execute (MovieController mc, int action, float value) {
  134.             System.out.println (mc + "," + "action:" + action + ",value=" + value);
  135.             return false; 
  136.         }
  137.     }
  138.  
  139.     //_________________________ Runtime Error Handling
  140.     static class Handler implements QTRuntimeHandler {
  141.         public void exceptionOccurred (QTRuntimeException e, Object eGenerator, String methodNameIfKnown, boolean unrecoverableFlag) {
  142.             System.out.println (eGenerator + "," + methodNameIfKnown + ",unrecoverable=" + unrecoverableFlag);
  143.             e.printStackTrace();
  144.             throw e;    // we don't handle this exception - just print stack trace and throw it
  145.         }
  146.     }
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.